package com.leyou.upload.controller;


import com.leyou.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @author syf
 * @version 1.0
 * @date 2019/08/01 17:26
 * @Description TODO:上传文件的控制器
 */
@RestController
@RequestMapping
public class UploadController {

    @Autowired
    private UploadService uploadService;

    /**
     * springBoot、nginx和网关默认上传文件大小都是1MB
     * 本地上传
     * @param file
     * @return
     */
    @PostMapping("/image")
    public ResponseEntity<String> uploadFileToNginx(MultipartFile file){
       String imgUrl= uploadService.uploadFileToNginx(file);
       return ResponseEntity.ok(imgUrl);
    }

    /**
     * 阿里oss签名
     * @return
     */
    @GetMapping("/signature")
    public ResponseEntity<Map<String,Object>>  getSignature(){
        return ResponseEntity.ok(uploadService.getSignature());
    }
}

